package com.ruoyi.intelligence.chat.chartGpt;

import com.plexpt.chatgpt.ChatGPT;
import com.plexpt.chatgpt.entity.chat.ChatCompletion;
import com.plexpt.chatgpt.entity.chat.ChatCompletionResponse;
import com.plexpt.chatgpt.entity.chat.Message;
import com.ruoyi.intelligence.chat.chartGpt.config.GptProperties;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;

/**
 * @Author: wxj
 * @Date: 2023/11/24
 */
public class ChartGPTService {


    @Autowired
    private GptProperties gptProperties;

    public  static void  chartGPT(){
        //国内需要代理 国外不需要
       // Proxy proxy = Proxys.http("127.0.0.1", 10809);
        ChatGPT chatGPT = ChatGPT.builder()
            .apiKey("sk-I4Rs3MkE2Jp3yise43B18dA32958436082349dB2Af6a3a49")
         //   .proxy(proxy)
            .timeout(900)
            .apiHost("https://api.qqslyx.com/") //反向代理地址
            .build()
            .init();

        Message system = Message.ofSystem("你现在是一个诗人，专门写七言绝句");
        Message message = Message.of("写一段七言绝句诗，题目是：火锅！");

        ChatCompletion chatCompletion = ChatCompletion.builder()
            .model(ChatCompletion.Model.GPT_4.getName())
            .messages(Arrays.asList(system, message))
            .maxTokens(3000)
            .temperature(0.9)
            .build();
        ChatCompletionResponse response = chatGPT.chatCompletion(chatCompletion);
        Message res = response.getChoices().get(0).getMessage();
        System.out.println(res);

    }


    public static void main(String[] args) {
        chartGPT();
    }

}
